package com.simon.queue;

import redis.clients.jedis.Jedis;

import java.util.Random;

/**
 * Created by changf on 2017/7/5.
 */
public class TaskConsumer {


    public static void main(String[] args) throws Exception{
        Jedis jedis = TaskProducer.getJedis("192.168.112.12", 6379);
        Random random=new Random();

        while(true) {
            String taskId = jedis.rpoplpush("task-queue", "tmp-queue");
            System.out.println("====get task-queue taskId:" + taskId);

            Thread.sleep(1000);

            int i = random.nextInt(13);
            if(i%7==0){
                //模拟失败
                jedis.rpoplpush("tmp-queue","task-queue");
                System.out.println("failure taskId:"+taskId);

            }else{
                jedis.rpop("tmp-queue");
                System.out.println("success taskId:"+taskId);
            }


        }

    }
}
